import org.aswing.plaf.custom.css.AbstractParser;
import org.aswing.plaf.custom.css.Components;
import org.aswing.plaf.custom.css.DefaultValues;
import org.aswing.plaf.ASFontUIResource;
import org.aswing.plaf.custom.css.TypedProperties;
import org.aswing.plaf.ASColorUIResource;

class org.aswing.plaf.custom.css.ComponentParser extends AbstractParser
{
	public static function parse(blockName,block:Object):Array{
		var result:Array = [];
		var UIDefaultsName:String = Components.getUIDefaultsComponentName(blockName) + ".";
		
		//font parsing
		var fontSize = block[CSS_FONT_SIZE];
		var fontName = block [CSS_FONT];
		var fontUIDefaultsName:String = UIDefaultsName + UIDEF_FONT;		
		if(fontName != null){
			if(fontSize != null)
				result = concat(result,[fontUIDefaultsName,new ASFontUIResource(fontName,fontSize)]);	
			else
				result = concat(result,[fontUIDefaultsName,new ASFontUIResource(fontName,DefaultValues.FONT_SIZE)]);				
		}else if(fontSize != null){
			result = concat(result,[fontUIDefaultsName,new ASFontUIResource(DefaultValues.FONT,fontSize)]);
		}
		
		//color parsing
		for (var i=0; i < TypedProperties.colours.length; i++) {
            var value:Number = Number(block[TypedProperties.colours[i]])			
			if (!isNaN(value)){
				trace ("color: " + UIDefaultsName + TypedProperties.colours[i] + ":"+ value)
				var UIDefColorName = TypedProperties.getUIDefaultsPropertyName(TypedProperties.colours[i]);
				var AwColor:ASColorUIResource = new ASColorUIResource(value);
				var colorName = UIDefaultsName + UIDefColorName
				result = concat(result, [UIDefaultsName + UIDefColorName, AwColor])
			}
        }
		
		
		return result;
	}
}
